$(function () {
    var pagenum = getParms("archives");
    if(pagenum=='')
        getArchivesByPageNum(1);
    else
        getArchivesByPageNum(pagenum);
})

function getArchivesByPageNum(pagenum) {
    $.post({
        url: baseurl+api.archives+pagenum,
        success: function (res) {
            if(res.code=="200"){
                var s="<span class=\"archive-move-on\"></span>\n" +
                    "                <span class=\"archive-page-counter\">There are "+res.data.archivesCount+" posts in total.posts in total till now</span>";
                map=res.data.archivesMap;
                for(var key in map){
                    var list=map[key];
                    s+=" <div class=\"collection-title\"><h2 class=\"archive-year motion-element\">"+key+"</h2></div>";
                    $.each(list,function (index, info) {
                        s+="<article class=\"post post-type-normal\" style=\"opacity: 1; display: block; transform: translateY(0px);\"><header class=\"post-header\"><h1 class=\"post-title\">\n" +
                            "                            <a class=\"post-title-link\" href='/detail/"+info.date+"/"+info.description+"'>\n" +
                            "                                <span>"+info.title+"</span></a></h1><div class=\"post-meta\">\n" +
                            "                            <time class=\"post-time\">"+info.date+"</time></div></header></article>";
                    })
                }
                pageination(res.data,"archives");
            }
            else {
                var s1="<span class=\"archive-move-on\"></span><span class=\"archive-page-counter\">There are 0 posts in total.posts in total till now</span>";
            }
            $("#posts").html(s);
        }
    })
}
function getParms(name) {
    var url= window.location.href;
    var index=url.indexOf(name);
    var s = url.substring(index+name.length+1);
    return s;
}